package com.edu.zju.scs.panacea.mapper.resource;

import com.edu.zju.scs.panacea.entity.manage.Admin;
import com.edu.zju.scs.panacea.entity.resource.Site;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SiteMapper {

    @Select("SELECT * FROM res_site WHERE id = #{id}")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name"),
            @Result(property="type",column="type")})
    Site selectSite(Long id);


    @Select("SELECT * FROM res_site")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name"),
            @Result(property="type",column="type")})
    List<Site> selectAllSite();

    @Delete("DELETE FROM res_site where id = #{id}")
    long deleteSite(Long id);

    @Insert("INSERT INTO res_site(own_id, name, type, password) VALUES(#{ownId}, #{name}, #{type}, #{password})")
    @Options(useGeneratedKeys=true)
    long insertSite(Site site);

    @Update({ "update res_site set own_id = #{ownId}, name = #{name}, type = #{type} where id = #{id}" })
    long updateSite(Site site);


    @Select("SELECT * FROM res_site WHERE name = #{name} and password = #{password}")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="ownId",column="own_id"),
            @Result(property="name",column="name"),
            @Result(property="type",column="type")})
    Site selectValidSite(String name, String password);

}
